using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.Loon.Framework.Xna.Game.Utils;

namespace Org.Loon.Framework.Xna.Game.Net
{
    public class HttpHeader
    {

        private string get;

        private string host;

        private string accept;

        private string referer;

        private string cookie;

        private string userAgent;

        private string userAgentValue;

        private string range;

        private string pragma;

        private string cacheControl;

        private string connection;

        public HttpHeader()
        {
            userAgentValue = UserAgents.RandomHumanAgent();
            get = "GET ";
            host = "Host: ";
            accept = "Accept: */*\r\n";
            referer = "Referer: ";
            cookie = "Cookie: ";
            userAgent = "User-Agent: " + userAgentValue + "\r\n";
            range = "Range: bytes=0-\r\n";
            pragma = "Pragma: no-cache\r\n";
            cacheControl = "Cache-Control: no-cache\r\n";
            connection = "Connection: close\r\n\r\n";
        }

        public void SetGet(string g)
        {
            int t = get.IndexOf(" ");
            get = StringUtils.Substring(get, 0, t + 1);
            get = get + g + "\r\n";
        }

        public void SetHost(string h)
        {
            int t = host.IndexOf(" ");
            host = StringUtils.Substring(host, 0, t + 1);
            host = host + h + "\r\n";
        }

        public void SetRange(string r)
        {
            int t = range.IndexOf("=");
            range = StringUtils.Substring(range, 0, t + 1);
            range = range + r + "\r\n";
        }

        public void SetReferer(string r)
        {
            int t = referer.IndexOf(":");
            referer = StringUtils.Substring(referer, 0, t + 1);
            referer = referer + r + "\r\n";
        }

        public void SetCookie(string c)
        {
            int t = cookie.IndexOf(":");
            cookie = StringUtils.Substring(cookie, 0, t + 1);
            cookie = cookie + c + "\r\n";
        }

        public string GetUserAgentValue()
        {
            return userAgentValue;
        }

        public string GetHeaderString()
        {
            return get + host + accept + userAgent + range + pragma + cacheControl
                    + connection;
        }
    }
}
